#include <stdio.h>
#include "ofc/DText.h"

int main(int argc, char *argv[])
{
  DText *str1 = [DText alloc];
  DText *str2 = [DText new  ];
  DText *str3 = [DText new  ];
  DText *str4 = [DText new  ];
  DText *str5 = [DText new  ];

                                       // String setters
  [str1 init :"  Initial  "];          // Init with a c-string

  [str2 format :"Form%ctted", 'a'];    // Set the string with a format

  [str3 set :"hello, this is a nice day"]; // Set the string

  [str4 set :"Substring" :2 :4];       // Set with substring

  [str5 set :'-' :15];                 // Make a string with 15 dashes

  printf("String setters: %s %s %s %s %s.\n", 
      [str1 cstring], [str2 cstring], [str3 cstring], [str4 cstring], [str5 cstring]);

                                       // Character methods
  [str5 put :1 :'+'];                  // Put on index 1 a '+'
  
  printf("Last char in string1:%c.\n", [str1 get :-1]);

  [str5 delete :0];                    // Remove the first character from string5

                                       // Slice methods
  [str4 insert :1 :-1 :"string"];      // Replace st to string in string4

  [str5 insert :2 :4 :'+' :4];         // Replace [2,4] to ++++ in string5

  [str5 delete :6 :10];                // Remove a substring from string5

  printf ("String lengths: %ld %ld %ld %ld %ld.\n",
      [str1 length], [str2 length], [str3 length], [str4 length], [str5 length]);

                                       // String manipulation
  [str4 prepend :"Su"];                // Prepend to make Substring

  [str4 multiply :2];                  // Multiply substring twice

  [str3 capwords];                     // Capitalize all words in string3

  [str1 lower];                        // Lower all caps in string1

  [str1 strip];                        // Strip all leading and trailing spaces

  [str2 rjust :15];                    // Right justify string2

                                       // Results
  printf("Results: %s %s %s %s %s.\n", 
      [str1 cstring], [str2 cstring], [str3 cstring], [str4 cstring], [str5 cstring]);

                                       // String compare 
  if ([str1 compare :str4] == 0)
    printf("String1 and string4 are equal.\n");
  else
    if ([str1 compare :str4] < 0)
      printf("String1 is smaller than string4.\n");
    else
      printf("String1 is bigger than string4.\n");
  
  return 0;
}
